<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="author" content="BaiYY"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/bootstrap.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/Font/css/font-awesome.min.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/index.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/pages.css"/>
    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/index.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/pages.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/page2.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/time.js"></script>
    <script type="text/javascript" src="__PUBLIC__/admin/js/jquery.validate.min.js"></script>
    <style type="text/css">
        .main .input-group-addon{
            width: 120px;
        }
        .form-control{
            -webkit-appearance: none;
        }
        @media (max-width: 680px) {
            .modal-body div.special{
                height: 75px;
            }
        }
    </style>
</head>
<body>
    <div class="right-sidebar" style="max-width: 1200px">
        <ul class="nav nav-tabs" style="margin-bottom: 16px" role="tablist">
            <li role="presentation"><a href="aUser.html">代理审核</a></li>
            <li role="presentation"><a href="agentUserList.html">代理列表</a></li>
            <li role="presentation" class="active"><a href="agentUserSearch.html">代理搜索</a></li>
            <li role="presentation"><a href="agentUserBuy.html">购买记录</a></li>
            <li role="presentation"><a href="agentUserSell.html">充值记录</a></li>
        </ul>
        <div class="row">
            <div class="col-md-6" style="margin-top: 10px">
                <div class="input-group">
                    <input type="text" class="form-control" placeholder="请输入代理ID" id="search">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" id="btn">&emsp;查看&emsp;</button>
                    </span>
                </div>
            </div>
            <div class="col-md-6" style="line-height: 50px">
                <button class="btn btn-primary" id="buyBtn">购买详情</button>
                <button class="btn btn-primary" id="payBtn">充值详情</button>
                <button class='btn btn-primary' data-toggle='modal' data-target='#myModal' onclick="onHandel()">设置</button>
            </div>
        </div>
        <section class="main">
            <div class="row" style="margin-top: 10px;">
                <div class="col-md-6 text-center">
                    <div class="input-group">
                        <span class="input-group-addon">代理ID</span>
                        <input class="form-control" type="text" name="user_id" id="user_id" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">真实姓名</span>
                        <input class="form-control" type="text" name="tname" id="tname" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">微信昵称</span>
                        <input class="form-control" type="text" name="bname" id="bname" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">手机号码</span>
                        <input class="form-control" type="text" name="tel" id="tel" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">代理级别</span>
                        <input class="form-control" type="text" name="role" id="role" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">推荐人</span>
                        <input class="form-control" type="text" name="refer" id="refer" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">下级代理数</span>
                        <input class="form-control" type="text" name="total_refer" id="total_refer" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon" id="clubhide">{:L(GAME_CLUB_MEMEMBER)}</span>
                        <input class="form-control" type="text" name="clubMemenber" id="clubMemenber" disabled="disabled"  />
                    </div>
                </div>
                <div class="col-md-6 text-center">
                    <div class="input-group">
                        <span class="input-group-addon">剩余{:L(GAME_RESOURCE)}</span>
                        <input class="form-control" type="text" name="card_number" id="card_number" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">总返利额</span>
                        <input class="form-control" type="text" name="total_rebate" id="total_rebate" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">总消费额</span>
                        <input class="form-control" type="text" name="total_amount" id="total_amount" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">待提现额</span>
                        <input class="form-control" type="text" name="total_withdraw" id="total_withdraw" disabled="disabled" />
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">已提现额</span>
                        <input class="form-control" type="text" name="total_draw" id="total_draw" disabled="disabled" />
                    </div>

                    <div class="input-group">
                        <span class="input-group-addon">注册时间</span>
                        <input class="form-control" type="text" name="create_time" id="create_time" disabled="disabled" />
                    </div>
                </div>
            </div>
        </section>
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">代理设置</h4>
                    </div>
                    <div class="modal-body">
                        <h4>说明：</h4>
                        <div style="margin-bottom: 10px;">代理级别设置只能为1,2,3</div>
                        <div style="margin-bottom: 10px;">重置密码不填，是原始密码，填写则是修改原始密码</div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="input-group">
                                    <span class="input-group-addon">代理的ID</span>
                                    <input type="text" class="form-control" name="uidd" id="uidd" disabled="true">
                                </div>
                                <div class="input-group">
                                    <span class="input-group-addon">重置密码</span>
                                    <input type="password" class="form-control" name="repassword" id="repassword">
                                </div>
                                <div class="input-group" id="roles">
                                    <span class="input-group-addon">代理级别</span>
                                    <div class="form-control special" >
                                        <input type="radio"  name="role" value="1" id="role1">一级
                                        &emsp;
                                        <input type="radio"  name="role" value="2" id="role2">二级
                                        &emsp;&nbsp;
                                        <if condition='$level gt 2'>
                                        <input type="radio"  name="role" value="3" id="role3">三级
                                        &emsp;
                                        </if>
                                        <input type="radio"  name="role" value="0" id="role0">取消代理权限
                                    </div>
                                </div>
                                <div class="input-group" id="state">
                                    <span class="input-group-addon">账号状态</span>
                                    <div class="form-control" >
                                        <input type="radio"  name="state" value="1" id="radio1">恢复
                                        &emsp;
                                        <input type="radio"  name="state" value="0" id="radio0">封号
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="button" class="btn btn-primary" id="sbtn">保存</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <section class="pay" style="display: none;max-width: 800px">
            <!--给玩家充值的详细信息-->
            <div class="table-responsive">
                <table class="table" id="paylist" style="border: 1px solid #ddd;">
                    <thead>
                    <tr>
                        <th colspan="2">玩家ID</th>
                        <th colspan="2">充值的数量</th>
                        <th colspan="2">充值状态</th>
                        <th colspan="2">充值的时间</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <ul class="page" id="page2" style="width: 100%;overflow: hidden;"></ul>
        </section>
        <section class="buy" style="display: none;max-width: 800px">
            <div class="table-responsive">
                <table class="table" id="buylist" style="border: 1px solid #ddd;">
                    <thead>
                    <tr>
                        <th colspan="2">购买商品名称</th>
                        <th colspan="2">购买商品价格</th>
                        <th colspan="2">购买数量</th>
                        <th colspan="2">购买时间</th>
                    </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
            <ul class="page" id="page1" style="width: 100%;overflow: hidden;"></ul>
        </section>
    </div>

    <script type="text/javascript">
        $(function () {
            onClick("#buyBtn");
            onClick("#payBtn");
            var clubText = $.trim($("#clubhide").text());
            if(clubText == '' || clubText == 'GAME_CLUB_MEMEMBER') {
                $("#clubhide").closest("div").hide();
            };
        });
        $("#btn").on("click",function(){
            if(!$(".main").show()){
                $(".main").show();
            }
            $(".buy").hide();
            $(".pay").hide();
            var search = $.trim($("#search").val());
//            console.log(search);
            if(search == '') {
                alert("请输入要查询的代理ID！");
                return false;
            }else if(isNaN(search)) {
                alert("代理ID是数字!");
                window.location.href="{:U('Admin/Main/agentUserSearch')}";
                return false;
            }
            $.ajax({
                type:"post",
                async:false,
                url:"{:U('Admin/Main/agentUserSearchh')}",
                dataType:"json",
                data:{'user_id':search},
                success:function(data) {
//                    console.log(data);
                    if(data == 'error') {
                        alert("暂无记录！");
                    }else if(data == 'nodata') {
                        alert("抱歉输入的代理无效！");
                    }else{
                        if(data.agent.role == 1){
                            $("#role1").attr("checked",true);
                        }else if(data.agent.role == 2) {
                            $("#role2").attr("checked",true);
                        }else if(data.agent.role == 3) {
                            $("#role3").attr("checked",true);
                        }

                        if(data.agent.state == 1) {
                            $("#radio1").attr("checked",true);
                        }else if(data.agent.state){
                            $("#radio0").attr("checked",true);
                        }

                        if(data.msg.hasOwnProperty('clubMemberCount')) {
                            $("#clubMemenber").val(data.msg.clubMemberCount);
                        }else{
                            $("#clubMemenber").val('暂无');
                        }
                        var refers = "";
                        if(data.agent.refer == 0 || data.agent.refer == '') {
                            refers = '无';
                        }else{
                            refers = data.agent.refer;
                        }

                        $("#uidd").val(data.agent.user_id);
                        $("#user_id").val(data.agent.user_id);
                        $("#tname").val(data.agent.name);
                        $("#bname").val(data.msg.info.name);
                        $("#tel").val(data.agent.tel);
                        $("#total_rebate").val(data.agent.total_rebate);
                        $("#total_amount").val(data.agent.total_amount);
                        $("#total_withdraw").val((data.agent.total_rebate-data.agent.total_withdraw));
                        $("#total_draw").val(data.agent.total_withdraw);
                        $("#role").val(data.agent_name);
                        $("#refer").val(refers);
                        $("#total_refer").val(data.count);
                        $("#card_number").val(data.msg.status.card);
                        $("#create_time").val(getLocalTime(data.agent.create_time));
                    }
                }
            });

            $("#buyBtn").on("click",function () {
                $(".main").hide();
                $(".pay").hide();
                $(".buy").show();
                var search = $.trim($("#search").val());
                if(search == '') {
                    alert("请输入要查询的代理ID！");
                    return false;
                }else if(isNaN(search)) {
                    alert("代理ID是数字!");
                    window.location.href="{:U('Admin/Main/agentUserSearch')}";
                    return false;
                }
                $.ajax({
                    type:"get",
                    url:"{:U('Admin/Main/agentUserBuyDetail')}?user_id=" + search,
                    success:function (buys) {
//                        console.log(buys);
                        if(buys == 'error') {
                            alert("暂无记录！");
                        }else{
                            options={
                                "id":"page1",//显示页码的元素
                                "data":buys,//显示数据
                                "maxshowpageitem":2,//最多显示的页码个数
                                "pagelistcount":10,//每页显示数据个数
                                "callBack":function(res){
                                    var str = '';
                                    for(var i=0;i<res.length;i++) {
                                        str += "<tr><td colspan='2'>"+res[i].goods_name+"</td><td colspan='2'>"+res[i].amount+"</td><td colspan='2'>"+res[i].number+"</td><td colspan='2'>"+getLocalTime(res[i].add_time)+"</td></tr>";
                                    }
                                    $("#buylist tbody").html(str);
                                }
                            }
                            page.init(buys.length,1,options);
                        }
                    }
                })
            });


            $("#payBtn").on("click",function(){
                $(".main").hide();
                $(".buy").hide();
                $(".pay").show();
                var search = $.trim($("#search").val());
                if(search == '') {
                    alert("请输入要查询的代理ID！");
                    return false;
                }else if(isNaN(search)) {
                    alert("代理ID是数字!");
                    window.location.href="{:U('Admin/Main/agentUserSearch')}";
                    return false;
                }
                $.ajax({
                    type:"get",
                    url:"{:U('Admin/Main/agentUserPayDetail')}?user_id=" + search,
                    success:function (pays) {
//                        console.log(pays);
                        if(pays == 'error') {
                            $("#dataList").html("暂时没查询到数据！");
                        }else{
                            option={
                                "id":"page2",//显示页码的元素
                                "data":pays,//显示数据
                                "maxshowpageitem":2,//最多显示的页码个数
                                "pagelistcount":10,//每页显示数据个数
                                "callBack":function(res) {
                                    var str = '';
                                    var txt = '';
                                    for(var i=0;i<res.length;i++) {
                                        if(res[i].status == '1') {
                                            txt = '成功';
                                        }else if(res[i].status == '0') {
                                            txt = '失败';
                                        }
                                        str += "<tr><td colspan='2'>"+res[i].uid+"</td><td colspan='2'>"+res[i].number+"</td><td colspan='2'>"+txt+"</td><td colspan='2'>"+getLocalTime(res[i].add_time)+"</td></tr>";
                                    }
                                    $("#paylist tbody").html(str);
                                }
                            }
                            page2.init(pays.length,1,option);
                        }
                    }
            });
        });

            $("#sbtn").on("click",function(){
            var user_id = $("#user_id").val();
            var repassword = $("#repassword").val();
            var role = $("#roles input[name='role']:checked").val();
            var state = $("#state input[name='state']:checked").val();
//				console.log(user_id,repassword,role,state);
            if($.trim(repassword) == '') {
                $.ajax({
                    type:"post",
                    url:"{:U('Admin/Main/userInfoSet')}",
                    dataType:"json",
                    data:{'user_id':user_id,'role':role,'state':state},
                    success:function(data) {
                        if(data == 'success') {
                            alert("设置成功！");
                            window.location.href="{:U('Admin/Main/agentUserSearch')}";
                        }else if(data == 'error'){
                            alert("设置失败！");
                            window.location.href="{:U('Admin/Main/agentUserSearch')}";
                        }else if(data == 'sucdel') {
                            alert("取消代理权限成功！");
                            window.location.href="{:U('Admin/Main/agentUserSearch')}";
                        }else if(data == 'errdel') {
                            alert("取消代理权限失败！");
                            window.location.href="{:U('Admin/Main/agentUserSearch')}";
                        }
                    }
                });
            }else if($.trim(repassword) != '') {
                if($.trim(repassword).length<6) {
                    alert("密码长度大于6位数！");
                    $("#repassword").val('');
                    return false;
                }
                if($.trim(repassword).length>20) {
                    alert("密码最大长度小于20位数！");
                    $("#repassword").val('');
                    return false;
                }
                $.ajax({
                    url:"{:U('Admin/Main/userInfoSet')}",
                    dataType:"json",
                    data:{'user_id':user_id,'role':role,'state':state,'password':repassword},
                    success:function(data) {
                        if(data == 'success') {
                            alert("设置成功！");
                            window.location.href="{:U('Admin/Main/agentUserSearch')}";
                        }else if(data == 'error'){
                            alert("设置失败！");
                            window.location.href="{:U('Admin/Main/agentUserSearch')}";
                        }else if(data == 'faliure') {
                            alert("抱歉，暂无相关数据！");
                            window.location.href="{:U('Admin/Main/agentUserSearch')}";
                        }
                    }
                });
            }
        });
         });
        function onHandel() {
            if($(".main").hide()) {
                $(".main").show();
            }
            $(".buy").hide();
            $(".pay").hide();
        }

        function onClick(obj) {
            $(obj).on("click",function () {
                var search = $.trim($("#search").val());
                if(search == '' || search == null) {
                    alert("请输入要查询的代理ID!");
                }
            })
        }
    </script>
</body>
</html>